package com.dianping.cat.consumer.state.model.transform;

import com.dianping.cat.consumer.state.model.IEntity;
import com.dianping.cat.consumer.state.model.IVisitor;
import com.dianping.cat.consumer.state.model.entity.Detail;
import com.dianping.cat.consumer.state.model.entity.Machine;
import com.dianping.cat.consumer.state.model.entity.Message;
import com.dianping.cat.consumer.state.model.entity.ProcessDomain;
import com.dianping.cat.consumer.state.model.entity.StateReport;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  15 */   private Stack<Object> m_objs = new Stack();

  private StateReport m_stateReport;


  public DefaultMerger() {}

  public DefaultMerger(StateReport stateReport) {
/*  23 */     this.m_stateReport = stateReport;
    this.m_objs.push(stateReport);
  }


/*  28 */   public StateReport getStateReport() { return this.m_stateReport; }



  protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
    this.m_objs.push(to);
/*  37 */     from.accept(this);
/*  38 */     this.m_objs.pop();
  }


/*  42 */   protected void mergeDetail(Detail to, Detail from) { to.mergeAttributes(from); }



/*  46 */   protected void mergeMachine(Machine to, Machine from) { to.mergeAttributes(from); }



/*  50 */   protected void mergeMessage(Message to, Message from) { to.mergeAttributes(from); }


  protected void mergeProcessDomain(ProcessDomain to, ProcessDomain from) {
/*  54 */     to.mergeAttributes(from);
/*  55 */     to.getIps().addAll(from.getIps());
  }


/*  59 */   protected void mergeStateReport(StateReport to, StateReport from) { to.mergeAttributes(from); }



  public void visitDetail(Detail from) {
/*  64 */     Detail to = (Detail)this.m_objs.peek();

/*  66 */     mergeDetail(to, from);
/*  67 */     visitDetailChildren(to, from);
  }


  protected void visitDetailChildren(Detail to, Detail from) {}


  public void visitMachine(Machine from) {
/*  75 */     Machine to = (Machine)this.m_objs.peek();

/*  77 */     mergeMachine(to, from);
    visitMachineChildren(to, from);
  }

  protected void visitMachineChildren(Machine to, Machine from) {
/*  82 */     for (ProcessDomain source : from.getProcessDomains().values()) {
/*  83 */       ProcessDomain target = to.findProcessDomain(source.getName());

/*  85 */       if (target == null) {
/*  86 */         target = new ProcessDomain(source.getName());
/*  87 */         to.addProcessDomain(target);
      }

/*  90 */       this.m_objs.push(target);
/*  91 */       source.accept(this);
/*  92 */       this.m_objs.pop();
    }

/*  95 */     for (Message source : from.getMessages().values()) {
/*  96 */       Message target = to.findMessage(source.getId());

/*  98 */       if (target == null) {
/*  99 */         target = new Message(source.getId());
/* 100 */         to.addMessage(target);
      }

/* 103 */       this.m_objs.push(target);
/* 104 */       source.accept(this);
/* 105 */       this.m_objs.pop();
    }
  }


  public void visitMessage(Message from) {
/* 111 */     Message to = (Message)this.m_objs.peek();

/* 113 */     mergeMessage(to, from);
/* 114 */     visitMessageChildren(to, from);
  }


  protected void visitMessageChildren(Message to, Message from) {}


  public void visitProcessDomain(ProcessDomain from) {
/* 122 */     ProcessDomain to = (ProcessDomain)this.m_objs.peek();

/* 124 */     mergeProcessDomain(to, from);
/* 125 */     visitProcessDomainChildren(to, from);
  }

  protected void visitProcessDomainChildren(ProcessDomain to, ProcessDomain from) {
/* 129 */     for (Detail source : from.getDetails().values()) {
/* 130 */       Detail target = to.findDetail(source.getId());

/* 132 */       if (target == null) {
/* 133 */         target = new Detail(source.getId());
/* 134 */         to.addDetail(target);
      }

/* 137 */       this.m_objs.push(target);
/* 138 */       source.accept(this);
/* 139 */       this.m_objs.pop();
    }
  }


  public void visitStateReport(StateReport from) {
/* 145 */     StateReport to = (StateReport)this.m_objs.peek();

/* 147 */     mergeStateReport(to, from);
/* 148 */     visitStateReportChildren(to, from);
  }

  protected void visitStateReportChildren(StateReport to, StateReport from) {
/* 152 */     for (Machine source : from.getMachines().values()) {
/* 153 */       Machine target = to.findMachine(source.getIp());

/* 155 */       if (target == null) {
/* 156 */         target = new Machine(source.getIp());
/* 157 */         to.addMachine(target);
      }

/* 160 */       this.m_objs.push(target);
/* 161 */       source.accept(this);
/* 162 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/state/model/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */